/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.flowumi.controladores.profesor;

import com.flowumi.controladores.SessionFlowumiUtilBean;
import com.flowumi.entity.Cursos;
import com.flowumi.facade.AdminFacade;
import com.flowumi.facade.ProfesorFacade;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import org.apache.log4j.Logger;

/**
 *
 * @author ideacentre
 */
@ManagedBean
@RequestScoped
public class ProfesorListaCursosBean implements Serializable{

    private static final Logger LOGGER =
            Logger.getLogger(ProfesorDetalleCursoBean.class);
    @EJB
    ProfesorFacade profesorFacade;
    
    @ManagedProperty("#{sessionFlowumiUtil}")
    private SessionFlowumiUtilBean sessionFlowumiUtilBean;
    
    
    private List<Cursos> cursos;
    
    @ManagedProperty("#{sessionFlowumiUtil}")
    private SessionFlowumiUtilBean sessionBean;

    public void setSessionBean(SessionFlowumiUtilBean sessionBean) {
        this.sessionBean = sessionBean;
    }

    /**
     * Creates a new instance of ProfesorListaCurso
     */
    public ProfesorListaCursosBean() {
    }
    
    @PostConstruct
    public void init(){
        if (sessionBean.getUsuario().getIdRol() == null || sessionBean.getUsuario().getIdRol().getIdRol() != 2) {
            try {
                sessionBean.Desconectar();
                FacesContext.getCurrentInstance().getExternalContext().redirect("InicioSession.xhtml");
            } catch (IOException ex) {
                LOGGER.error(ex);
            }
        }
        cursos = profesorFacade.getListaCursosProfesor(sessionFlowumiUtilBean.getUsuario().getNombreUsuario());
    }
    
    public void setSessionFlowumiUtilBean(SessionFlowumiUtilBean sessionFlowumiUtilBean) {
        this.sessionFlowumiUtilBean = sessionFlowumiUtilBean;
    }

    public List<Cursos> getCursos() {
        return cursos;
    }

    public void setCursos(List<Cursos> cursos) {
        this.cursos = cursos;
    }
    
    public String verDetalleCurso(long idCurso){
        Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
        flash.put("idCurso", idCurso);
        return "/pages/ProfesorDetalleCurso.xhtml";
    }
}
